import React, { PureComponent, createRef } from 'react'

class HelloWorld extends PureComponent {
  test() {
    console.log('test----------');
  }
  render() {
    return <div>Hello World</div>
  }
}

function HelloWorldFunc() {
  return (
    <div>Hello World 函数组件</div>
  )
}

export class App extends PureComponent {
  constructor() {
    super()
    this.state = {}
    this.HWRef = createRef()
  }


  getComponentDOM() {
    console.log(this.HWRef.current);
    this.HWRef.current.test()
  }
  render() {
    return (
      <div>
        <HelloWorld ref={this.HWRef}></HelloWorld>
        <button onClick={() => this.getComponentDOM()}>获取HWRef</button>
        <HelloWorldFunc></HelloWorldFunc>
      </div>
    )
  }
}

export default App